#include <iostream>
#include <list>
#include <queue>
using namespace std;

struct Node {
	int i, m;
	Node(int a, int b): i(a), m(b){}
};

int main()
{
	int n, m; cin >> n;
	list<Node> list;
	for (int i = 1; i <= n; i++) {
		cin >> m;
		list.push_back({ i, m });
	}
	cin >> m;
	int jug = 0;
	for (auto& node : list) {
		if (jug) cout << "->"; jug = 1;
		cout << "(" << node.i << "," << node.m << ")";
	}
	cout << "\n\n";
	for (auto it = list.begin(); list.size() > 1; it = list.erase(it)) {
		if (it == list.end()) it = list.begin();
		while (--m) if (++it == list.end()) it = list.begin();
		cout << (*it).i << "->";
		m = (*it).m;
	}
	cout << list.front().i;
	return 0;
}